package com.example.myapplication.screen

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp

@Composable
fun TextFiledDemo(innerPadding: PaddingValues){
    //用户名、密码、年龄、个人介绍
    var username by remember { mutableStateOf("") }
    var password by remember { mutableStateOf("") }
    var age by remember { mutableStateOf("") }
    var introduce by remember { mutableStateOf("") }

    Column(
        modifier = Modifier.fillMaxSize().padding(innerPadding),
        verticalArrangement = Arrangement.Top
    ) {
        TextField(
            textStyle = TextStyle(color = Color.Blue, fontWeight = FontWeight.Bold),
            colors = TextFieldDefaults. colors(cursorColor = Color.Red, unfocusedContainerColor = Color.White, focusedContainerColor = Color.LightGray),
            modifier = Modifier
                .fillMaxWidth(),
            value = username,
            label = { Text(text = "请求输入用户名") },
            onValueChange = {username = it},
            singleLine = true
        )

        //2.密码框
        TextField(
            modifier = Modifier
                .fillMaxWidth(),
            value = password,
            onValueChange = { password = it },
            //label = {Text("请输入密码")},
            singleLine = true,
            visualTransformation = PasswordVisualTransformation()
        )

        //3.数字输入框
        TextField(
            modifier = Modifier
                .fillMaxWidth(),
            value = age,
            onValueChange = { age = it },
            label = {Text("请输入年龄")},
            singleLine = true,
            keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number)
        )

        //4.多行文本框
        TextField(
            value = introduce,
            onValueChange = { introduce = it },
            label = { Text("个人介绍") },
            maxLines = 5,
            modifier = Modifier.height(100.dp).fillMaxWidth()
        )

        Button(
            onClick = {
                println("用户名：$username")
                println("密码：$password")
                println("年龄：$age")
                println("个人介绍：$introduce")
            }
        ) {
            Text(text = "获取输入的信息")
        }
    }
}